/*
 * @Author: your name
 * @Date: 2020-12-29 10:29:53
 * @LastEditTime: 2021-02-23 09:51:09
 * @LastEditors: 熊燕萍
 * @Description: In User Settings Edit
 * @FilePath: \ys.oltest\src\ys\map\index.js
 */
import 'ol/ol.css'

import ysLayer from './layer'
import ysMap from './map'
import ysMarker from './marker'
import ysFormat from './format'
import ysPolygon from './polygon'
import ysPolyline from './polyline'
import ysControl from './control'
import ysInteraction from './interaction'

function Map(containerId,centerCoor,zoom,proj,minZoom,maxZoom){
  this.map = ysMap.init(containerId,centerCoor,zoom,proj,minZoom,maxZoom);
  this.view = this.map.getView();
  this.layer = new ysLayer(this.map);
  this.marker = new ysMarker(this.map);
  this.format = new ysFormat(this.map);
  this.polygon = new ysPolygon(this.map);
  this.polyline = new ysPolyline(this.map);
  this.control = new ysControl(this.map);
  this.interaction = new ysInteraction(this.map);
}

/**
 * @description: 设置显示中心
 * @param {array} lonlat 中心点经纬度
 * @param {int} zoom 缩放级别 
 * @return {*}
 */
Map.prototype.panTo = function(lonlat,zoom){
  if(zoom){
    this.view.animate({
      zoom: zoom,
      center: lonlat,
      duration: 1000
    });
  }
  else {
    this.view.animate({
      center: lonlat,
      duration: 1000 //动画效果时间
    })
  };
};

Map.prototype.moveToExtent = function(extent) {
  this.map.getView().fit(extent,{duration:800});
}

export default Map
